<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>#{bundel.loan}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
            <h:form>
                <script type="text/javascript">  
                    function handleSaveRequest(xhr, status, args) {  
                        if(args.validationFailed || !args.success) {  
                            jQuery('#dialog').effect("shake", { times:3 }, 100);  
                        } else {  
                            dlgLoaninfo.hide();  
                        }  
                    }
                    
                    
                    function componenKeyPressLoanInfo(e) {
                    var code = (e.keyCode ? e.keyCode : e.which);
                    if(code==13) {
                        cmdSearchLoanInfo.jq.click();
                        e.preventDefault();
                    }
					}
                </script>  
               
                <p:toolbar>
                    <p:toolbarGroup align="left">
                        <p:commandButton value="#{bundle.btnOpen}" icon="ui-icon-disk"
                                         action="#{loanInfoBean.openWorksheet()}" update=":#{utilityBean.findClientId('displayLoanapproval')}" oncomplete="dlgLoaninfo.show();">
                            <f:param value="#{loginBean.selectedUser.userId}" name="userId" />  
                        </p:commandButton>
                       
                        <p:commandButton value="Refresh" icon="ui-icon-search" update=":#{utilityBean.findClientId('dtLoaninfo')}" 
                                         actionListener="#{loanInfoBean.loadLoan()}" >
                            <f:param value="#{loginBean.selectedUser.userId}" name="userId" />
                        </p:commandButton>
                        
                        
                    </p:toolbarGroup>
                     <p:toolbarGroup align="right">
                    <h:panelGrid columns="3" cellpadding="0" cellspacing="0">  
                        <p:inputText size="30" onkeyup="upperCase(this)" id="loanInfoSearch" value="#{loanInfoBean.filter}" onkeypress="componenKeyPressLoanInfo(event)" />  
                        <p:watermark for="loanInfoSearch" value="#{bundle.loanNo} or Nama" />  
                        
                        <p:commandButton widgetVar="cmdSearchLoanInfo" icon="ui-icon-search" update="dtLoaninfo" 
                                         actionListener="#{loanInfoBean.search()}" /> 
                    </h:panelGrid>  
                </p:toolbarGroup>
                </p:toolbar>
                
                <p:dataTable id="dtLoaninfo" value="#{loanInfoBean.loans}" var="loanapprove" 
                    selection="#{loanInfoBean.loan}" selectionMode="single" 
                    rowKey="#{loanapprove.loanId}" sortBy="#{loanapprove.loanNo}"
                    paginator="true" rows="10" paginatorPosition="bottom" rowsPerPageTemplate="5,10,15,30" 
                    paginatorTemplate="{CurrentPageReport} {PreviousPageLink} {NextPageLink} {RowsPerPageDropdown}"
                    scrollable="false" scrollWidth="1100" resizableColumns="true">
                                        
                    <p:column style="width: 90px" headerText="#{bundle.loanNo}" >
                        <h:outputText value="#{loanapprove.loanNo}" />
                    </p:column>

                  <!--  <p:column style="width: 90px" headerText="#{bundle.cif}" >
                        <h:outputText value="#{loanapprove.customer.cif}" />
                    </p:column>
                      -->                  
                    <p:column style="width: 130px" headerText="#{bundle.customer}" >
                        <h:outputText value="#{loanapprove.customer.customerName}" />
                    </p:column>
                      <p:column style="width: 230px" headerText="#{bundle.addressId}" >
                        <h:outputText value="#{loanapprove.customer.idAddressLine1}" />
                    </p:column>          
                      <p:column style="width: 80px" headerText="#{bundle.loanDate}" >
                        <h:outputText value="#{loanapprove.loanDate}" />
                    </p:column>
                      <p:column style="width: 80px" headerText="#{bundle.dueDate}" >
                        <h:outputText value="#{loanapprove.dueDate}" />
                    </p:column>
                    
                    <p:column style="width: 130px" headerText="#{bundle.savprod}" >
                        <h:outputText value="#{loanapprove.loanprod.productName}" />
                    </p:column>

                      <p:column style="width: 80px" headerText="#{bundle.interestRate}" >
                        <h:outputText value="#{loanapprove.interestRate}" >
                            <f:convertNumber />
                        </h:outputText>
                    </p:column>
                    <p:column style="width: 80px" headerText="#{bundle.loanAmount}" >
                        <h:outputText value="#{loanapprove.principalAmount}" >
                            <f:convertNumber />
                        </h:outputText>
                    </p:column>
                      <p:column style="width: 80px" headerText="#{bundle.bakiDebet}" >
                        <h:outputText value="#{loanapprove.owningAmount}" >
                            <f:convertNumber />
                        </h:outputText>
                    </p:column>
                </p:dataTable>
            </h:form>
            
            <p:dialog header="Informasi Pinjaman" widgetVar="dlgLoaninfo" closable="true" dynamic="true" 
                      appendToBody="true" modal="true" >
                <p:ajax immediate="true" event="close" listener="#{loanInfoBean.handleClose}"/>
                <h:form>
				<p:tabView>
					<p:tab title="Data">
                    <h:panelGrid id="displayLoanapproval" styleClass="addELIT" cellpadding="0" border="0" > 
                        <h:panelGrid columns="2" rowClasses="panelGridId" >
                            <p:panel header="#{bundle.loanLedgend}" rendered="#{loanInfoBean.loan != null}">
                                <h:panelGrid columns="3" cellpadding="0" cellspacing="10">
                                    <h:outputLabel value= "#{bundle.cif}" /><h:outputLabel value= ":" />
                                    <h:outputLabel value="#{loanInfoBean.loan.customer.cif}" />

                                    <h:outputLabel value= "#{bundle.loanprod}" /><h:outputLabel value= ":" />
                                    <h:outputLabel value="#{loanInfoBean.loan.loanprod.productName}" />

                                    <h:outputLabel value= "#{bundle.loanDate}" /><h:outputLabel value= ":" />
                                    <h:outputText value="#{loanInfoBean.loan.loanDate}" />

                                    <h:outputLabel value= "#{bundle.loanNo}" /><h:outputLabel value= ":" />
                                    <h:outputText value="#{loanInfoBean.loan.loanNo}" />

                                    <h:outputLabel value= "#{bundle.loanAmount}" /><h:outputLabel value= ":" />
                                    <h:outputText value="#{loanInfoBean.loan.principalAmount}" >
                                        <f:convertNumber groupingUsed="true"/>
                                    </h:outputText>        

                                    <h:outputLabel value= "#{bundle.tenor}" /><h:outputLabel value= ":" />
                                    <p:selectBooleanCheckbox value="#{loanInfoBean.loan.tenor}" disabled="true" />

                                    <h:outputLabel style="padding:0 15px 0 0;" value= "#{bundle.interestRate}" /><h:outputLabel value= ":" />
                                    <h:outputLabel value="#{loanInfoBean.loan.interestRate} %" >
                                        <f:convertNumber groupingUsed="true"/>
                                    </h:outputLabel>    

                                    <h:outputLabel value= "#{bundle.interestType}" /><h:outputLabel value= ":" />
                                    <h:outputLabel value="#{constantaBean.getInterestTypeText(loanInfoBean.loan.interestType)}" />

                                    <h:outputLabel value= "#{bundle.disbursementDate}" /><h:outputLabel value= ":" />
                                    <p:calendar disabled="true" value="#{loanInfoBean.loan.disbursementDate}" pattern="dd/MM/yyyy" size="8" navigator="true"/>
                                   
                                    <h:outputLabel value= "#{bundle.period}" /><h:outputLabel value= " : " />
                                    <h:outputText value="#{loanInfoBean.loan.period}" >
                                        <f:convertNumber groupingUsed="true"/>
                                    </h:outputText>
                                      
                                    <h:outputLabel value= "#{bundle.dueDate}" /><h:outputLabel value= " : " />
                                    <p:calendar disabled="true" value="#{loanInfoBean.loan.dueDate}" pattern="dd/MM/yyyy" size="8" 
                                                selectOtherMonths="true" navigator="true"/>
                                    <h:outputLabel value= "#{bundle.paypoint}" /><h:outputLabel value= " : " />
                                    <h:panelGrid columns="2" cellpadding="0" cellspacing="0" >
                                        <p:selectOneMenu value="#{loanInfoBean.loan.paypointId}" style="width: 151px;" disabled="true">
                                            <f:selectItems value="#{loanInfoBean.avblPoint}" />
                                        </p:selectOneMenu>
                                    </h:panelGrid>
                                </h:panelGrid>

                                <h:panelGrid columns="0" style="width: 100%;" >
                                    
                                
                                    <p:toolbar>
                                        <p:toolbarGroup align="left" >
                                            <h:outputText value="#{bundle.loanfee}" />
                                        </p:toolbarGroup>
                                    </p:toolbar>
                                    
                                    <p:dataTable var="fee" value="#{loanInfoBean.loan.loancosts}" >
                                        <p:column style="width:auto;">
                                            <f:facet name="header">#{bundle.fee}</f:facet>
                                            <h:outputText value="#{loanInfoBean.selectItemValueOf(loanInfoBean.availableFee, fee.feeId)}" />
                                        </p:column>
                                        <p:column style="width: 50px;">
                                            <f:facet name="header">#{bundle.feepc}</f:facet>
                                            <h:outputLabel value="#{fee.feePc}" styleClass="numPos" >
                                                <f:convertNumber groupingUsed="true" />
                                            </h:outputLabel>
                                        </p:column>

                                        <p:column style="width: 80px;">
                                            <f:facet name="header">#{bundle.amount}</f:facet>
                                            <h:outputLabel value="#{fee.feeAmount}" styleClass="numPos" >
                                                <f:convertNumber groupingUsed="true" />
                                            </h:outputLabel>
                                        </p:column>
                                    </p:dataTable>
                                </h:panelGrid>
                                
                                <h:panelGrid columns="0" style="width: 100%;" >
                                    <p:toolbar>
                                        <p:toolbarGroup align="left" >
                                            <h:outputText value="#{bundle.loancoral}" />
                                        </p:toolbarGroup>
                                    </p:toolbar>

                                    <p:dataTable var="coral" value="#{loanInfoBean.loan.loancorals}" rendered="#{loanInfoBean.loan != null}">
                                        <p:column headerText="#{bundle.collateral}" style="width:100px">
                                            <h:outputText value="#{loanInfoBean.selectItemValueOf(loanInfoBean.avaibleCoral, coral.collateralId)}" style="width:100px;" />
                                        </p:column>

                                        <p:column headerText="#{bundle.bookValue}" style="width: 15px">
                                            <h:outputText value="#{coral.bookValue}" styleClass="numPos">
                                                <f:convertNumber  />
                                            </h:outputText>
                                        </p:column>

                                        <p:column headerText="#{bundle.documentNo}" style="width: 15px">
                                            <h:outputText value="#{coral.documentNo}" />
                                        </p:column>

                                        <p:column headerText="#{bundle.documentDate}" style="width: 15px">
                                            <h:outputText value="#{coral.documentDate}" />
                                        </p:column>

                                    </p:dataTable> 
                                </h:panelGrid>        
                            </p:panel>  

                            <h:panelGrid columns="1" cellpadding="1" rowClasses="panelGridId" border="0" >
                                <p:panel header="#{bundle.cusledgen}" rendered="#{loanInfoBean.loan != null}">
                                    <p:outputPanel autoUpdate="true">
                                    <h:panelGrid columns="3" cellpadding="0" cellspacing="10">

                                        <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                                        <h:outputText style="padding: 0 75px 0 0;"  value="#{loanInfoBean.loan.customer.customerName}" />

                                        <h:outputLabel value= "#{bundle.aliasName}" /><h:outputLabel value= ":" />
                                        <h:outputText rendered="true" value="#{loanInfoBean.loan.customer.aliasName}" />

                                        <h:outputLabel value= "#{bundle.phone}" /><h:outputLabel value= ":" />
                                        <h:outputText value="#{loanInfoBean.loan.customer.phone}"/> 

                                        <h:outputLabel value= "#{bundle.mobilePhone}" /><h:outputLabel value= ":" />
                                        <h:outputText value="#{loanInfoBean.loan.customer.mobilePhone}"/>

                                        <h:outputLabel style="padding: 0 15px 0 0;"  value= "#{bundle.npwp}" /><h:outputLabel value= ":" />
                                        <h:outputText value="#{loanInfoBean.loan.customer.npwp}" />

                                        <h:outputLabel style="padding: 0 15px 0 0;"  value= "#{bundle.addressRes}" /><h:outputLabel value= ":" />
                                        <h:outputText value="#{loanInfoBean.loan.customer.idAddressLine1}" />

                                    </h:panelGrid>
                                    </p:outputPanel>
                                </p:panel>

                                <p:panel header="#{bundle.loanprodLedgend}" rendered="#{loanInfoBean.loan != null}">
                                    <p:outputPanel autoUpdate="true">
                                    <h:panelGrid columns="3" cellpadding="0" cellspacing="10">
                                        <h:outputLabel style="padding: 0 15px 0 0;" value= "#{bundle.gpInslateDays}" /><h:outputLabel value= ":" />
                                       <h:outputText rendered="true" value="#{loanInfoBean.loan.loanprod.gpInslateDays} #{bundle.day}" />

                                        <h:outputLabel value= "#{bundle.penaltyInslateRate}" /><h:outputLabel value= ":" />
                                        <h:outputText rendered="true" value="#{loanInfoBean.loan.loanprod.penaltyInslateRate} %" />

                                        <h:outputLabel value= "#{bundle.interestType}" /><h:outputLabel value= ":" />
                                        <h:outputText rendered="true" value="#{constantaBean.getInterestTypeText(loanInfoBean.loan.loanprod.interestType)}" />

                                        <h:outputLabel value= "#{bundle.closingPenaltyRate}" /><h:outputLabel value= ":" />
                                        <h:outputText rendered="true" value="#{loanInfoBean.loan.loanprod.closingPenaltyRate} %" />

                                    </h:panelGrid>
                                </p:outputPanel>        
                                </p:panel>
								
								
						
								
                            </h:panelGrid>
                        </h:panelGrid>    
                    </h:panelGrid>
                    </p:tab>
                    <p:tab title="SIMULASI ANGSURAN">
					<p:panel header="SIMULASI ANGSURAN">
                                            <p:dataTable scrollable="true" scrollHeight="350" resizableColumns="true"  id="dtLoanInfosim" value="#{loanInfoBean.loansimulates}" var="simulasi" rowIndexVar="noUrut">
                            
                                <p:column style="width: 12px;">
                                    <f:facet name="header">No</f:facet>
                                    <h:outputText value="#{noUrut+1}" />
                                </p:column>

                                <p:column style="width: 50px;">
                                    <f:facet name="header">#{bundle.date}</f:facet>
                                    <h:outputText value="#{simulasi.date}" />
                                </p:column>

                                <p:column style="width: 85px;">
                                    <f:facet name="header">Angsuran Pokok</f:facet>
                                    <h:outputText value="#{simulasi.amount}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>

                                <p:column style="width: 75px;">
                                    <f:facet name="header">Bunga</f:facet>
                                    <h:outputText value="#{simulasi.interest}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>

                                <p:column style="width: 90px;">
                                    <f:facet name="header">Total</f:facet>
                                    <h:outputText value="#{simulasi.total}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>
                                   <p:column style="width: 90px;">
                                       <f:facet name="header">Os Pokok  </f:facet>
                                       <h:outputText value="#{simulasi.outstanding}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>   
                                 <p:column style="width: 90px;">
                                     <f:facet name="header">Os Bunga</f:facet>
                                       <h:outputText value="#{simulasi.outstandingInterest}" styleClass="numPos" >
                                        <f:convertNumber />
                                    </h:outputText>
                                </p:column>  
                                <p:column style="width: 100px;">
                                    <f:facet name="header">Keterangan</f:facet>
                                    <h:outputText value="#{simulasi.description}"  />
                                </p:column>
                                <p:columnGroup type="footer">  
                                    <p:row>  
                                       <p:column style="text-align:right" footerText="" />    
                                        <p:column style="text-align:right" footerText="Total:"/> 
                                        
                                        <p:column style="text-align:right" footerText="#{loanInfoBean.pricipalAmounts}" />    
                                        <p:column style="text-align:right" footerText="#{loanInfoBean.interestAmounts}" />    
                                        <p:column style="text-align:right" footerText="#{loanInfoBean.amounts}" />    
                                        <p:column style="text-align:right" footerText="" />    
                                        <p:column style="text-align:right" footerText="" />    
                                        <p:column style="text-align:right" footerText="" />    
                                    </p:row>
                                </p:columnGroup>
                                 

                            </p:dataTable>
                        </p:panel>
						
                    </p:tab>
                    </p:tabView>
                    <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                        <f:facet name="footer">  
       <!--                     <p:commandButton value="#{bundle.approved}" icon="ui-icon-disk" 
                                             actionListener="#{loanInfoBean.approve(true, loginBean.selectedUser.userId)}"
                                             update=":#{utilityBean.findClientId('dtLoaninfo')}" oncomplete="handleSaveRequest(xhr, status, args)"/>  
                            
                            <p:commandButton value="#{bundle.rejected}" icon="ui-icon-disk" 
                                             actionListener="#{loanInfoBean.approve(false, loginBean.selectedUser.userId)}"
                                             update=":#{utilityBean.findClientId('dtLoaninfo')}" oncomplete="handleSaveRequest(xhr, status, args)"/>  
           -->                                             
                            <p:commandButton value="#{bundle.btnClose}" immediate="true" oncomplete="dlgLoaninfo.hide()" 
                                icon="ui-icon-document" />
                        </f:facet>
                    </h:panelGrid>
                </h:form>
            </p:dialog> 
            
        </ui:composition>
    </h:body>
</html>